package com.lyy.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyy.common.utils.UUIDUtils;
import com.lyy.project.dao.ProProjectDao;
import com.lyy.project.pojo.ProProject;
import com.lyy.project.service.ProProjectService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 项目信息(ProProject)表服务实现类
 *
 * @author Yw
 * @since 2021-02-01 17:22:25
 */
@Service
public class ProProjectServiceImpl extends ServiceImpl<ProProjectDao, ProProject> implements ProProjectService {


    /**
     * 添加项目信息
     *
     * @param proProject
     */
    @Override
    public void createProProject(ProProject proProject) {
        proProject.setCreateDate(new Date());
        proProject.setDelFlag("0");
        baseMapper.insert(proProject);
    }

    /**
     * 根据主键修改项目信息
     *
     * @param proProject
     */
    @Override
    public void updateProProject(ProProject proProject) {
        proProject.setUpdateDate(new Date());
        baseMapper.update(proProject, new UpdateWrapper<ProProject>()
                .eq("id", proProject.getId())
        );
    }

    /**
     * 根据主键删除项目信息
     *
     * @param id 项目id
     * @return
     */
    @Override
    public void deleteProProject(ProProject proProject) {
        baseMapper.delete(new UpdateWrapper<ProProject>()
                .eq("id", proProject.getId())
        );
    }

    /**
     * 根据主键查询项目信息详情
     *
     * @param id 项目id
     * @return
     */
    @Override
    public ProProject getProProject(ProProject proProject) {
        return baseMapper.selectOne(new QueryWrapper<ProProject>()
                .eq("id", proProject.getId())
        );
    }

    /**
     * 批量添加项目信息
     *
     * @param proProjects
     */
    @Override
    public int batchInsert(List<ProProject> proProjects) {
        return baseMapper.batchInsert(proProjects);
    }


    /**
     * 批量修改项目信息
     *
     * @param proProjects
     */
    @Override
    public int batchUpdate(List<ProProject> proProjects) {
        return baseMapper.batchUpdate(proProjects);
    }

    /**
     * 查询项目信息列表
     *
     * @param proProject
     */
    @Override
    public List<ProProject> selectProProjectList(ProProject proProject) {
        return baseMapper.selectProProjectList(proProject);
    }

    /**
     * 查询项目信息数量
     *
     * @param proProject
     */
    @Override
    public int selectProProjectCount(ProProject proProject) {
        return baseMapper.selectProProjectCount(proProject);
    }


    /**
     * 导入项目信息excel
     *
     * @param proProjects
     */
    @Override
    public List<Map<String, String>> importProProjectExcel(List<ProProject> proProjects) {
        List<Map<String, String>> mapList = new ArrayList<>();
        proProjects.forEach(proProject -> {
            proProject.setId(UUIDUtils.getUUIDTWO());
            Map<String, String> map = new HashMap<>();
            map.put("status", "0");
            map.put("reason", "导入成功");
            mapList.add(map);
        });
        batchInsert(proProjects);
        return mapList;
    }
}